package com.chandon.juc.container.queue;

import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * 描述
 *
 * @author Dong
 */

public class ArrayBlockingQueueTest {

	static ArrayBlockingQueue<String> stringsblockingQueue = new ArrayBlockingQueue<>(100);
	public static void main(String[] args) {
		add();
		take();
		while (true);
	}

	public static void add() {

		new Thread(() -> {
			for (int i = 0; i < 100; i++) {

				stringsblockingQueue.offer("add" + i);
			}
		}).start();

	}

	public static void take(){

		new Thread(() -> {
			while (true) {
				String poll = stringsblockingQueue.poll();
				if (Objects.nonNull(poll)) {
					System.out.println(poll);
				}
			}
		}).start();

	}
}
